package com.sharemedia.utils
{
	import com.sharemedia.consts.AppConst;

	public class RatingUtil
	{
		private static const MIN_LISTENERS:Number = 10;
		
		public static function computeRating(likeNum:Number, unlikeNum:Number):Number
		{
			if(likeNum+unlikeNum == 0)
				return 0;
			
			var neutral:Number = MIN_LISTENERS-(likeNum+unlikeNum);
			neutral = neutral > 0 ? neutral : 0;
			
			var result:Number = (neutral*AppConst.RATING_RANGE/2 + likeNum*AppConst.RATING_RANGE)/(likeNum+unlikeNum+neutral);
			result = Math.ceil(result*10)/10;
			return result;
		}
	}
}